/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package plash.text;

import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import plash.geom.Rectangle;
import plash.utils.Logger;

/**
 *
 * @author User
 */
public class TextFormat
{

    private String _align = TextFieldAutoSize.LEFT;
    private String _font = "Tahoma";
    
    private int _color = 0x000000;    
    private int _indent = 2;    
    private int _kerning;
    private int _leading = 3;
    private int _leftMargin = 3;
    private int _letterSpacing = 1;
    private int _rightMargin = 3;
    private int _size = 22;
    
    private boolean _underline = false;
    private boolean _italic = false;
    private boolean _bold = false;
    
    private Font _javaFont;

    public TextFormat()
    {
        _updateFont();
    }
    
    private void _updateFont()
    {
        int style = Font.PLAIN;
        if(this._bold)
        {
            style = style | Font.BOLD;
        }
        if(this._italic)
        {
            style = style | Font.ITALIC;
        }
        _javaFont = new Font(_font, style, _size * (72 / 96));        
    }
    
//    public Rectangle getTextExtent(Graphics javaGraphics, String text, int width)
//    {
//        
//    }
    
    public Rectangle getTextExtent(Graphics javaGraphics, String text)
    {
        FontMetrics metrics = javaGraphics.getFontMetrics(_javaFont);
        
        return new Rectangle(0,0,metrics.stringWidth(text),metrics.getHeight());
    }

    public String getAlign()
    {
        return _align;
    }

    public void setAlign(String align)
    {
        this._align = align;
    }

    public String getFont()
    {
        return _font;
    }

    public void setFont(String font)
    {
        this._font = font;
        _updateFont();
    }

    public int getColor()
    {
        return _color;
    }

    public void setColor(int color)
    {
        this._color = color;
    }

    public int getIndent()
    {
        return _indent;
    }

    public void setIndent(int indent)
    {
        this._indent = indent;
    }

    public boolean isItalic()
    {
        return _italic;
    }

    public void setItalic(boolean italic)
    {
        this._italic = italic;
        _updateFont();
    }

    public int getKerning()
    {
        return _kerning;
    }

    public void setKerning(int kerning)
    {
        this._kerning = kerning;
    }

    public int getLeading()
    {
        return _leading;
    }

    public void setLeading(int leading)
    {
        this._leading = leading;
    }

    public int getLeftMargin()
    {
        return _leftMargin;
    }

    public void setLeftMargin(int leftMargin)
    {
        this._leftMargin = leftMargin;
    }

    public int getLetterSpacing()
    {
        return _letterSpacing;
    }

    public void setLetterSpacing(int letterSpacing)
    {
        this._letterSpacing = letterSpacing;
    }

    public int getRightMargin()
    {
        return _rightMargin;
    }

    public void setRightMargin(int rightMargin)
    {
        this._rightMargin = rightMargin;
    }

    public int getSize()
    {
        return _size;
    }

    public void setSize(int size)
    {
        this._size = size;
        _updateFont();
    }

    public boolean isUnderline()
    {
        return _underline;
    }

    public void setUnderline(boolean underline)
    {
        this._underline = underline;
    }

    public boolean isBold()
    {
        return _bold;
    }

    public void setBold(boolean bold)
    {
        this._bold = bold;
        _updateFont();
    }
}
